#include "Socket.h"

Socket::Socket()
{
	m_socket = nullptr;
}

Socket::Socket(const TCPsocket& s)
{
	m_socket = s;
}


bool Socket::Send(const SocketMessage& sm)
{
	int result = SDLNet_TCP_Send(m_socket, sm.GetData(), sm.GetLength());
	return (result <= 0);
}

bool Socket::Receive(SocketMessage* sm)
{
	char msg[2000];
	int result = SDLNet_TCP_Recv(m_socket, msg, 2000);
	msg[result] = 0;
	sm->WriteInt((int)msg);
	return true;
}

bool Socket::Close()
{
	SDLNet_TCP_Close(m_socket);

	return true;
}

bool Socket::HasData()
{
	return true;
	//return m_socket;
}

bool Socket::IsOpen()
{
	return m_socket;
}